import json
import os
L = []
#for root,dirs,files in os.walk('./'):
#for root,dirs,files in os.walk('./0json_test/'):
#    for file in files:
#        if os.path.splitext(file)[1]=='.json':
#            L.append(root+file)

src_dir = './'
for file in os.listdir(src_dir):
    if os.path.splitext(file)[1] == '.json':
        L.append(src_dir + file)


for pic_num in range (len(L)):
#for pic_num in range (1):
    index = 1
    with open(L[pic_num],"r", encoding='utf-8') as f:
        result = json.load(f)
    shapes = result["shapes"]
    for shape in shapes:
        if(shape["label"][0]!="0"):
            shape["label"] = str(index).zfill(3)+shape["label"]
        else:
            shape["label"] = shape["label"][3:]
        index += 1
    with open('out.json','w', encoding='utf-8') as f:
        data = json.dump(result,f,ensure_ascii=False,indent=4)